package cn.toutatis.sandbox.root;

import cn.toutatis.common.controllerDepand.CommonWrapper;
import cn.toutatis.sandbox.root.systemService.entity.SystemMenu;
import cn.toutatis.sandbox.root.systemService.service.SystemMenuService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author Toutatis_Gc
 */

@RestController
public class RootController {

    @Autowired
    SystemMenuService systemMenuService;

    @RequestMapping("/")
    public ModelAndView index(HttpServletRequest request){
        int i = 1/ 0 ;
        ModelAndView modelAndView = new ModelAndView("root/INDEX");
        return modelAndView;
    }

    @RequestMapping("/background")
    public ModelAndView background(){
        ModelAndView modelAndView = new ModelAndView("root/System");
        CommonWrapper systemMenuCommonWrapper = CommonWrapper.getInstance();
        QueryWrapper<SystemMenu> openWrapper = systemMenuCommonWrapper.selectOpenWrapper();
        List<SystemMenu> menuList = systemMenuService.list(openWrapper);
        modelAndView.addObject("menuList",menuList);
        return modelAndView;
    }

    @RequestMapping("/root/systemRuntimeInfo")
    public ModelAndView systemRuntimeInfo(){
        ModelAndView runtime = new ModelAndView("root/system/setting/SystemRuntimeInfo");
        //TODO  系统信息
        return runtime;
    }


    @RequestMapping("/errorInfo")
    public ModelAndView error(String code){
        ModelAndView modelAndView = new ModelAndView("root/system/error/SimpleErrorPage");
        modelAndView.addObject("code",code);
        return modelAndView;
    }

}
